home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / smaltalk / st80_pr4.lha / st80_pre4 / Foible / foible / FoibleBinIO-PP.st < prev    next >
Text File  |  1993-07-24  |  4KB  |  126 lines

  1. 'From Objectworks for Smalltalk-80(tm), Version 2.5 of 29 July 1989 on 16 April 1990 at 8:45:08 pm'!
  2.  
  3.  
  4. !Tool methodsFor: 'layout messages'!
  5.  
  6. open
  7.     "Ask for a filename, and make the model the result of reading 
  8.     the structure in that file"
  9.  
  10.     | aName aFoibleProgram |
  11.     aName _ (FillInTheBlank request: 'Open what layout file?') asFilename.
  12.     aName = '' ifTrue: [^nil].
  13.     aName exists ifFalse: [^PopUpNotifier message: aName , ' does not exist.'].
  14.     Cursor wait show.
  15.     aFoibleProgram _ FoibleProgram readStructureFromFile: aName.
  16.     model cursor show.
  17.     view superView class openOn: aFoibleProgram!
  18.  
  19. save
  20.     "Ask for a filename, and save the model in that file"
  21.  
  22.     | aName result |
  23.     aName _ (FillInTheBlank request: 'Save in what file?' initialAnswer: self program name,'.stbin').
  24.     aName = '' ifTrue: [^nil].
  25. aName _ aName asFilename.
  26.     aName exists
  27.         ifTrue: 
  28.             [result _ BinaryChoice message: 'File ' , aName , ' already exists.
  29. Do you want to overwrite it?'.
  30.             result ifFalse: [^nil]].
  31.     Cursor wait show.
  32.     self program storeStructureOnFile: aName.
  33.     model cursor show! !
  34.  
  35. Model subclass: #FoibleProgram
  36.     instanceVariableNames: 'name managers '
  37.     classVariableNames: ''
  38.     poolDictionaries: ''
  39.     category: 'Foible'!
  40.  
  41.  
  42. !FoibleProgram methodsFor: 'accessing'!
  43.  
  44. managers
  45.     "return the managers"
  46.  
  47.     ^managers! !
  48.  
  49. !FoibleProgram methodsFor: 'saving'!
  50.  
  51. storeStructureOnFile: aFileName 
  52.     "Uses binary storage save a copy of the Foible program; don't save 
  53.     dependents with it. Breaks the managers dependents before saving 
  54.     and restores them afterwards."
  55.  
  56.     | aFoibleProgram dependentsList deps |
  57.     aFoibleProgram _ self copy.    "get a copy without dependents."
  58.     managers _ aFoibleProgram managers.
  59.     dependentsList _ OrderedCollection new.
  60.     managers do: 
  61.         [:aManager | 
  62.         dependentsList add: aManager dependents.
  63.         aManager breakDependents].
  64.     BinaryStorage put: aFoibleProgram onFileNamed: aFileName.
  65.     managers do: 
  66.         [:aManager | 
  67.         deps _ dependentsList at: (managers indexOf: aManager).
  68.         deps do: [:aDependent | aManager addDependent: aDependent]]! !
  69.  
  70. !FoibleProgram methodsFor: 'public binary storage'!
  71.  
  72. storeBinary
  73.     "Writes a description of the receiver into a file, in a way that allows
  74.      the object's structure to be reconstructed from the file's contents."
  75.  
  76.     | fileName savedCursor |
  77.     fileName _ FileDirectory
  78.                     requestFileName: 'Store binary on which file name?'
  79.                     default: (self name, '.stbin')
  80.                     version: #any
  81.                     ifFail: [^nil].
  82.  
  83.     savedCursor _ Cursor currentCursor.
  84.     Cursor wait show.
  85.     self storeStructureOnFile: fileName.
  86.     savedCursor show.! !
  87.  
  88.  
  89. !FoibleProgram class methodsFor: 'instance creation'!
  90.  
  91. readStructureFromFile: aFileName 
  92.     "Read from a disk file a saved FoibleProgram whose instance variable 
  93.     'managers' is initialized to be an OrderedCollection containing 
  94.     one (or more) FoibleManagers.  The FoibleProgram must have been 
  95.     saved with ObjectWorks BOSS."
  96.  
  97.     | newFoibleProgram |
  98.     newFoibleProgram _ BinaryStorage fromFileNamed: aFileName.
  99.     ^newFoibleProgram! !
  100.  
  101. !ToolBenchView class methodsFor: 'instance creation'!
  102.  
  103. openProgram
  104.     "Open an existing program; saved as a binary"
  105.     "ToolBenchView openProgram" 
  106.  
  107.     | aFileName |
  108.     aFileName _ FileDirectory
  109.                 requestFileName: 'Which layout do you want to open?'
  110.                 default: '*.stbin'
  111.                 version: #any
  112.                 ifFail: [^nil].
  113.     aFileName asFilename exists ifFalse: [^PopUpNotifier message: aFileName , ' does not exist.'].
  114.     self openOn: (FoibleProgram readStructureFromFile: aFileName)!
  115.  
  116. openProgram: aName 
  117.     "Open an existing program saved as a binary"
  118.     "ToolBenchView openProgram: <name>"
  119.  
  120.     | aFileName |
  121.     aFileName _ aName asFilename.
  122.     aFileName exists ifFalse: [^PopUpNotifier message: aFileName asString , ' does not exist.'].
  123.     self openOn: (FoibleProgram readStructureFromFile: aFileName)! !
  124.  
  125.  
  126.